package com.bible.fire.pad.activity.aspect;

import java.util.ArrayList;
import java.util.List;

import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.provider.Settings;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.bible.fire.R;
import com.bible.fire.local.AppContext;
import com.bible.fire.local.SettingManager;
import com.bible.fire.pad.activity.BaseActivity;
import com.bible.fire.util.AndroidUtil;
import com.bible.fire.util.ToastUtil;
import com.bible.fire.util.WindowUtil;
import com.bible.test.pad.activity.AutoLocateBMapActivity;
import com.bible.test.pad.activity.CameraActivity;
import com.bible.test.pad.activity.GPSLocateActivity;
import com.bible.test.pad.activity.HttpSpeedTestActivity;
import com.bible.test.pad.activity.Simple2CodeActivity;
import com.bible.test.pad.activity.SimpleBaiduMapActivity;
import com.bible.test.pad.activity.TabDemoActivity;
import com.bible.test.pad.activity.actionbar.ActionBarDisplayOptions;
import com.bible.test.pad.activity.actionbar.ActionBarMechanics;
import com.bible.test.pad.activity.actionbar.ActionBarTabs;
import com.bible.test.pad.activity.fragment.BriefImageActivity;
import com.bible.test.pad.activity.group.MainTabFrame;
import com.bible.test.pad.activity.listview.ListViewDemo;
import com.bible.test.pad.activity.listview.MyListView;

public class TestActivity extends BaseActivity {
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_test);
		mListView = (ListView)findViewById(R.id.listView);
		// 添加ListItem，设置事件响应
				List<String> data = new ArrayList<String>();
				for (int i = 0; i < mStrDemos.length; i++) {
					data.add(mStrDemos[i]);
				}
		        mListView.setAdapter((ListAdapter) new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,data));
		        mListView.setOnItemClickListener(new OnItemClickListener() {  
		            public void onItemClick(AdapterView<?> arg0, View v, int index, long arg3) {  
		            	onListItemClick(index);
		            }  
		        });
		        
	}
	
	
	
	void onListItemClick(int index) {
    	if ( index < mActivities.length ){    	
			Intent intent = null;
			intent = new Intent(TestActivity.this, mActivities[index]);
			this.startActivity(intent);
    	}else{
    		showDialog( mStrDemos[index].substring(mStrDemos[index].indexOf("(") + 1, mStrDemos[index].length()-1));
    	}
    }
	
	void showDialog(String info){
		if( "Location".equalsIgnoreCase( info ) ){
			double[] positions = AndroidUtil.getCurrentLocation();
			String deviceId = AndroidUtil.getDeviceId();
			String sn = AndroidUtil.getSerialNumber();
			if( positions != null && positions.length == 2 ){
				this.showAlertDialog("纬度:" + positions[0] + ",经度:" + positions[1] + ",设备号：" + deviceId + ",序列号：" + sn);
			}else{
				this.showAlertDialog("设备号：" + deviceId + ",序列号：" + sn + ",无法获取当前位置信息");
			}
		}else if( "gps".equalsIgnoreCase( info ) ){
			SettingManager.checkGPSSetting( this );
		}else if( "float_window".equalsIgnoreCase( info ) ){
			
			//Toast.makeText(TestActivity.this, "app: " + AndroidUtil.getAttribute("app"), Toast.LENGTH_LONG ).show();
			//WindowUtil.showTip("谁把我点出来的 : " + AndroidUtil.getAttribute("app"));
			//ToastUtil.showMsg(TestActivity.this, "字体设置");			
			showProgressDialog();
		}else{
			this.showAlertDialog("∧_∧,点错了!");
		}
	}

	
	@Override
	// 建议在APP整体退出之前调用Api的destroy()函数，不要在每个activity的OnDestroy中调用，
    // 避免Api重复创建初始化，提高效率
	protected void onDestroy() {
		AppContext app = (AppContext)this.getApplication();
		if (app.mBMapManager != null) {
			app.mBMapManager.destroy();
			app.mBMapManager = null;
		}
		super.onDestroy();
	}
	
	ListView mListView = null;
    String mStrDemos[] = {
    		"Http速度测试",
    		"tab测试",
            "拍照",
            "创建一张地图(百度)",
            "自动定位我的位置(百度)",
            "通过GPS定位标注(百度)",
            "简单二维码",
            "TAB选项卡",
            "ActivityGroup",
            "ActionBarDisplayOptions",
            "ActionBarMechanics",
            "ActionBarTabs",
            "listview",
            "listViewDemo",
            "缩略图左右视图",
            "当前位置(Location)",
            "开关设置(GPS)",
            "悬浮窗口(float_window)"
    };
    Class<?> mActivities[] = {
    		HttpSpeedTestActivity.class,
    		TabDemoActivity.class,
    		CameraActivity.class,
            SimpleBaiduMapActivity.class,
            AutoLocateBMapActivity.class,
            GPSLocateActivity.class,
            Simple2CodeActivity.class,
            TabDemoActivity.class,
            MainTabFrame.class,
            ActionBarDisplayOptions.class,
            ActionBarMechanics.class,           
            ActionBarTabs.class,
            MyListView.class,           
            ListViewDemo.class,
            BriefImageActivity.class
            /*
            RoutePlanDemo.class,
            BusLineSearchDemo.class,
            GeoCoderDemo.class,
            LocationOverlayDemo.class,
            CloudSearchDemo.class,
            OfflineDemo.class */
    };

}
